// pages/mine/anchorWelfare/anchorWelfareRe.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //主要信息
    balance: [],
    code: '',
    extract_time: 0,
    receive_time: 0,

    //参数
    rpx: '',
    page: 1,

    //弹框
    flag_rule: true,
    flag_ruleTwo: true,

    flag_update: false,
  },
  go_detail(){
    wx.navigateTo({
      url: '../welfareDetail/welfareDetail',
    })
  },
  //去任务
  go_task() {
    wx.redirectTo({
      url: '../../earns/earns'
    })
  },
  //隐藏弹框
  modal_hide() {
    this.setData({
      flag_share: true,
      flag_update: false,
    })
  },
  //取得规则
  getRule() {
    wx.request({
      url: app.globalData.url + 'api/broker/lift/rule',
      data: {
        token: app.globalData.token,
      },
      method: 'POST',
      success: (e) => {
        let welfare = e.data.data.welfare,
          rule = e.data.data.rule,
          upgrade = e.data.data;
        this.setData({
          upgrade: upgrade,
        })
      },

    })
  },
  //加载个人信息
  getInfo() {
    wx.request({
      url: app.globalData.url + 'api/common/register/info',
      data: {
        token: app.globalData.token,
      },
      method: 'POST',
      success: (e) => {
        console.log(e)
        let info = e.data.data,
          realMoney = parseInt(info.bb) ? parseInt(info.bb) / this.data.balance.bb_rate : 0;
        this.setData({
          info: info,
          realMoney: realMoney,
        })
      },
    })
  },
  //显示规则
  click_showrule() {
    this.setData({
      flag_rule: false,
    })
  },
  //隐藏
  click_hide() {
    this.setData({
      flag_rule: true,
      flag_ruleTwo: true,
    })
  },
  //点击 提现
  change_withdraw() {
    wx.request({
      url: app.globalData.url + 'api/invitation/apply/condition',
      data: {
        token: app.globalData.token,
      },
      method: 'POST',
      success: (e) => {
        console.log(e)
        let type = e.data.data.type;
        this.setData({
          type: type,
        })
        if (type == 7) {
          console.log("提现中")
        }else {
          wx.navigateTo({
            url: 'anchorWelfare_detail/anchorWelfare_detail',
          })
        }
      },
    })
  },
  //获取我的额度 等信息
  balance() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/invitation/my/balance',
      data: {
        token: app.globalData.token,
      },
      method: 'POST',
      success: function (e) {
        // console.log(e)
        let balance = e.data.data;
        let code = e.data.data.code;
        that.setData({
          balance: balance,
          code: code,
        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.balance();
    this.getInfo();
    this.getRule();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})